<template>
	<view class="detail" v-if="info">
		<view class="report">
			<view class="" style="flex: 1;"></view>
			<view @click="center = true" class="jb">举报</view>
			<view class="lh" @click="block">拉黑</view>
		</view>
		<view class="info">
			<view class="title flex up"  @click="copy(info.name)">
				<image v-if="info.is_top == 1" src="../../static/videoShoppingDetail/up.png" mode=""></image>
				[{{info.infocate}}]{{info.name}}
			</view>
			<view class="bottom flex f-y-c f-x-b">
				<view class="user flex f-y-c">
					<view class="image bgImg" :style="{backgroundImage: `url(${info.userInfo.avatar})`}"></view>
					<view class="name">{{info.userInfo.nickname}}</view>
				</view>
				<view class="time">{{info.createtime | date}} 发布了文章</view>
			</view>
		</view>
		<view class="content" @click="copy(info.content)">
			{{info.content}}
		</view>
		<view class="covers" v-for="(item,index) of info.images" :key="index">
			<image  @click="swiperGo(oss(item))" :src="oss(item)" class="cover" mode="widthFix"></image>
		</view>
		<view class="covers" v-if="info.video">
			<video class="cover" :src="oss(info.video)"></video>
			<view class="overlay" v-if="info.switch != 1">该用户暂无开通视频功能</view>
		</view>
		
		
		<view class="" style="margin-top: 62rpx;"></view>
		<view class="" style="text-align: center;font-size: 32rpx;font-weight: 800;">
			为你推荐
		</view>
		<view class="list">
			<view class="item" :class="{up: index == 0}" v-for="(item,index) of list"
				@click="todetail(item.id)">
				<view class="title flex" :class="{top: item.is_top == 1}">
					<image v-if="item.is_top == 1" src="../../static/videoShoppingDetail/up.png" mode=""></image>
					[{{item.infocate}}]{{item.name}} <image v-if="item.video" style="width: 38rpx;height: 38rpx;vertical-align: middle;padding-left: 5rpx;" src="../../static/video.png" mode=""></image>
				</view>
				<view class="bottom flex f-y-c f-x-b">
					<view class="user flex f-y-c">
						<view class="image bgImg" :style="{backgroundImage: `url(${item.userInfo.avatar})`}"></view>
						<view class="name">{{item.userInfo.nickname}}</view>
					</view>
					<view class="time">{{item.createtime | date}} 发布</view>
				</view>
			</view>
		</view>
		
		<view class="fixedBottom fixed flex f-x-b">
			<view class="user flex f-y-c">
				<view class="image bgImg" :style="{backgroundImage: `url(${info.userInfo.avatar})`}"></view>
				<view class="name">{{info.userInfo.nickname}}</view>
			</view>
			<view style="display: flex;align-items: center;">
				<w-btn borderRadius="30rpx" type="common2" width="289.75rpx" height="83.77rpx" @click="tel">
					<image src="../../static/back_mobile.png" mode=""></image>
					联系电话
				</w-btn>
				<view style="width: 30rpx;height: 1rpx;"></view>
				<w-btn borderRadius="30rpx" type="common2" width="140.75rpx" height="83.77rpx" @click="playPinnedShow">
					帮他置顶
				</w-btn>
			</view>
		</view>
		<!-- 置顶弹窗 -->
		<TopPopup :ispublish="0" :show1="pinnedShow" :meal="meal" @padlock="padlock" @ckeck="ckeck"></TopPopup>
		
		
		
		<u-popup mode="center" :round="10" :show="center" @close="close" @open="open">
			<view class="popup-center">
				<view class="title">举报内容</view>
				<view class="input">
					<!-- <input v-model="nickname" placeholder="请输入新的昵称" type="text"> -->
					<u--textarea v-model="content" placeholder="请填写举报内容..." autoHeight ></u--textarea>
				</view>
				<view class="btn">
					<view @click="center = false" class="cancel">取消</view>
					<view @click="submit" class="confirm">确定</view>
				</view>
			</view>
		</u-popup>
		
		<!-- 一键分享 -->
		<view class="share">
		    <u-button id="shareBtn" open-type="share">分享</u-button>
		</view>
	</view>
</template>

<script>
	import TopPopup from "@/components/topPopup.vue"
	export default {
		components: {
			TopPopup
		},
		data() {
			return {
				id: '',
				info: '',
				center: false,
				content:'',
				
				page: 1,
				triggered: false,
				_freshing: false,
				lock: false,
				finish: false,
				list: [],
				
				pinnedShow:false,//置顶弹窗
				paytype:2,
				meal:[],
				myMoney:0
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getInfo()
			this.getList()
			
			if(uni.getStorageSync('token')){
				this.getcombo()
				this.getMoney()
			}
			// #ifdef MP-WEIXIN
			this.paytype = 2
			// #endif
			// #ifdef APP
			this.paytype = 1
			// #endif
		},
		onShareTimeline(){
		    return{
		      title:this.info.name,  //分享的标题
		      query:{
				  id:this.id
			  },     //点击分享链接之后进入的页面路径
		      imageUrl:'', // 设置分享卡片图片
		    }
		},
		onReachBottom() {
			this.lower()
		},
		methods: {
			playPinnedShow(){
				if(!uni.getStorageSync('token')){
					uni.$u.route({
						url: 'pagesA/auth/login'
					})
					return
				}
				this.pinnedShow = true
			},
			getMoney(){
				uni.$u.http.post('/getmoney ').then(res => {
					if (res.code === 1) {
						this.myMoney = res.data
					}
				}).catch((res) => {
					
				})
			},
			ckeck(e) {
				if(!e.id) return this.toast('请选择置顶套餐')
				if(this.myMoney < e.money){
					//余额不足 微信支付
					uni.$u.http.post('/meallist', {
						type:0,
						order_id:this.id,
						id:e.id,
						paytype:this.paytype
					}).then(res => {
						console.log(res)
						if (res.code == 1) {
							let that = this
							uni.requestPayment({
								appId: res.data.pay.appId,
								nonceStr: res.data.pay.nonceStr,
								package: res.data.pay.package,
								paySign: res.data.pay.paySign,
								signType: res.data.pay.signType,
								timeStamp: res.data.pay.timeStamp,
								success: (e) => {
									that.toast(res.msg)
									that.pinnedShow = false
								},
								fail: (e) => {
									that.$u.toast('支付失败');
								}
							})
						}
					}).catch((res) => {
							
					})
				}else {
					//余额支付
					uni.$u.http.post('/meallist', {
						type:0,
						order_id:this.id,
						id:e.id,
						paytype:4
					}).then(res => {
						console.log(res)
						if (res.code == 1) {
							this.toast(res.msg)
							this.pinnedShow = false
						}
					}).catch((res) => {
							
					})
				}
			},
			// 取消置顶
			padlock(){
				this.pinnedShow = false
			},
			//置顶套餐
			getcombo() {
				uni.$u.http.post('/meallist',{
					mealtype:0
				}).then(res => {
					if (res.code == 1) {
						this.meal = res.data
					}
				}).catch((res) => {
				})
			},
			
			lower() {
				this.page++
				this.getList()
			},
			todetail(id){
				console.log(id,'..........')
				uni.redirectTo({
					url:'/pages/forum/detail?id=' + id
				})
			},
			getList() {
				if (this.finish) {
					return
				}
				uni.$u.http.post('/infolist', {
					page: this.page,
					cate_id:''
				}).then(res => {
					this.lock = false
					this.triggered = false;
					this._freshing = false;
					if (res.code == 1) {
						console.log(res.data)
						for (let i = 0; i < res.data.length; i++) {
							if (res.data[i].images) {
								res.data[i].images = res.data[i].images.map(value => {
									return this.oss(value)
								})
							}
			
						}
						console.log(res.data)
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {
			
				})
			},
			swiperGo(img){
				uni.previewImage({
					urls:[img],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			submit(){
				if (!this.content) {
					uni.$u.toast('请输入举报内容');
					return;
				}
				uni.$u.http.post('/report', {
					content:this.content
				}).then(res => {
					if (res.code == 1) {
						this.center = false
						uni.$u.toast(res.msg);
						this.content = ''
					}
				}).catch((res) => {
				
				})
			},
			open() {
				// console.log('open');
			},
			close() {
				this.center = false
				// console.log('close');
			},
			change(e) {
				console.log('change', e);
			},
			//拉黑
			block(){
				uni.$u.toast('已拉黑');
			},
			showimage(e) {
				console.log(e)
				uni.previewImage({
					urls: [this.info.images[e]]
				})
			},
			tel() {
				// if(!uni.getStorageSync('token')){
				// 	uni.$u.route({
				// 		url: 'pagesA/auth/login'
				// 	})
				// 	return
				// }
				uni.makePhoneCall({
					phoneNumber: this.info.mobile
				});
			},
			getInfo() {
				uni.$u.http.post('/infos', {
					id: this.id,
					type: 'info'
				}).then(res => {
					if (res.code == 1) {
						console.log(res.data)
						if (res.data.images) {
							res.data.images = res.data.images.map(value => {
								return this.oss(value)
							})
						}
						this.info = res.data
						// for(let i=0; i < res.data.length; i++){

						// }
						// console.log(res.data)
						// this.list = this.list.concat(res.data)
						// if (res.data.length === 0) {
						// 	this.finish = true
						// }
					}
				}).catch((res) => {

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.detail {
		padding: 0 37.4rpx 160rpx;
		.covers{
			padding: 20rpx 0;
			position: relative;
			.cover{
				width: 100%;
			}
			.overlay {
			  position: absolute;
			  top: 0;
			  left: 0;
			  width: 100%;
			  height: 420rpx;
			  backdrop-filter: blur(10px); /* 添加模糊效果 */
			  text-align: center;
			  line-height: 400rpx;
			  font-size: 24rpx;
			  color: #FEBF4E;
			}
		}
		
		.report {
			display: flex;
			
			.jb {
				font-size: 24rpx;
				background-color: #FEBF4E;
				padding: 5rpx 20rpx;
				align-items: center;
				border-radius: 20rpx;
				margin-right: 20rpx;
			}
			.lh {
				font-size: 24rpx;
				background-color: #FEBF4E;
				padding: 5rpx 20rpx;
				align-items: center;
				border-radius: 20rpx;
			}
		}
		
		.info {
			padding: 51rpx 0 40rpx;
			border-bottom: 1rpx solid #EAEAEA;
			margin-bottom: 50rpx;

			.title {
				font-size: 32rpx;
				font-weight: 600;
				line-height: 1.3;
				color: #000000;

				&.up {
					color: #EA0000;
				}

				image {
					width: 38rpx;
					height: 38rpx;
					flex-shrink: 0;
					margin-right: 10rpx;
					transform: translateY(4rpx);
				}
			}

			.bottom {
				margin-top: 35rpx;

				.user {
					.image {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						background-color: #D8D8D8;
						margin-right: 15rpx;
					}

					.name {
						font-size: 30rpx;
						font-weight: 400;
						color: rgba(0, 0, 0, 0.8);
					}
				}

				.time {
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.3);
				}
			}
		}
		
		
		.list {
			padding: 20rpx;
			background: #fff;
			padding: 0 32rpx;
		
			.item {
				padding: 51rpx 0 40rpx;
				border-bottom: 1rpx solid #EAEAEA;
		
				.title {
					font-size: 32rpx;
					font-weight: 600;
					line-height: 1.3;
					color: #000000;
		
					&.up {
						color: #EA0000;
					}
		
					image {
						width: 38rpx;
						height: 38rpx;
						flex-shrink: 0;
						margin-right: 10rpx;
						transform: translateY(4rpx);
					}
				}
				.top{
					color: #EA0000;
				}
		
				.bottom {
					margin-top: 35rpx;
		
					.user {
						.image {
							width: 40rpx;
							height: 40rpx;
							border-radius: 50%;
							background-color: #D8D8D8;
							margin-right: 15rpx;
						}
		
						.name {
							font-size: 30rpx;
							font-weight: 400;
							color: rgba(0, 0, 0, 0.8);
						}
					}
		
					.time {
						font-size: 24rpx;
						font-weight: 400;
						color: rgba(0, 0, 0, 0.3);
					}
				}
			}
		}
		
		
		

		.fixedBottom {
			border-top: 1rpx solid #E7E7E7;
			bottom: 0;
			left: 0;
			right: 0;
			padding-top: 30rpx;
			padding-bottom: 30rpx;
			padding-bottom: calc(30rpx + constant(safe-area-inset-bottom));
			padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
			padding-left: 31.54rpx;
			padding-right: 42.38rpx;
			background: #fff;

			.user {
				.image {
					width: 79rpx;
					height: 79rpx;
					border-radius: 50%;
					margin-right: 20rpx;
				}

				.name {
					font-size: 32rpx;
					font-weight: 400;
					color: #3D3D3D;
				}
			}

			.btn {
				image {
					width: 28.56rpx;
					height: 28.56rpx;
					margin-right: 11rpx;
				}
			}
		}
		
		.popup-center {
			width: 600rpx;
			min-height: 360rpx;
		
			.title {
				text-align: center;
				margin-top: 46rpx;
				font-size: 34rpx;
			}
		
			.input {
				width: 480rpx;
				// height: 92rpx;
				background-color: #F7F7F7;
				margin: auto;
				margin-top: 46rpx;
				text-align: center;
		
				input {
					position: relative;
					top: 20rpx;
				}
			}
		
			.btn {
				width: 100%;
				height: 90rpx;
				margin-top: 20rpx;
				display: flex;
				// background-color: darkcyan;
		
				.cancel {
					width: 49%;
					height: 100%;
					text-align: center;
					line-height: 90rpx;
					font-size: 28rpx;
					color: #999;
					border-top: 1rpx solid #f3f3f3;
					border-right: 1rpx solid #f3f3f3;
				}
		
				.confirm {
					width: 49%;
					text-align: center;
					line-height: 90rpx;
					font-size: 28rpx;
					color: #FEBF4E;
					border-top: 1rpx solid #f3f3f3;
				}
			}
		}
	}
	
	
	.share {
				background-color: #FEBF4E;
				color: #333;
				border-radius: 50%;
				position: fixed;
				bottom: 300rpx;
				right: 29rpx;
				z-index: 9;
				#shareBtn {
					background-color: #FEBF4E;
					color: #333;
					width: 100%;
					height: 100%;
					position: absolute;
					top: 0;
					left: 0;
					opacity: 0;
				}
			}
			/deep/ .u-button--info.data-v-2bf0e569 {
				background-color: #FEBF4E !important;
				border-style: none;
			}
</style>
